package com.dongdxiang.framework.http;

import android.content.Context;
import android.graphics.Bitmap;
import android.widget.ImageView;

import com.google.gson.reflect.TypeToken;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.rest.CacheMode;
import com.yolanda.nohttp.rest.Request;
import com.yolanda.nohttp.rest.Response;

/**
 * Created by d_xxiang on 2016/11/2.
 */
public class ImageLoader{
    public static void disImage(Context context, String url, final ImageView imageView){
        Request<Bitmap> imageRequest = NoHttp.createImageRequest(url);//这里
        imageRequest.setCacheMode(CacheMode.NONE_CACHE_REQUEST_NETWORK);
        CallServer.getRequestInstance().add(context, 0, imageRequest, new HttpListener<Bitmap>() {
            @Override
            public void onSucceed(int what, Response<Bitmap> response, TypeToken typeToken, Object object) {
                ((ImageView)object).setImageBitmap(response.get());
            }

            @Override
            public void onFailed(int what, String url, Object tag, Exception exception, int responseCode, long networkMillis) {
                String str = what+exception.toString()+responseCode;
            }
        }, null,imageView, true, false);
    }

}
